home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Sources) / Standard Controls / Buttons / XGStdPushButton.cpp < prev    next >
Text File  |  1997-04-24  |  4KB  |  163 lines

  1. /*    XGStdPushButton
  2.  *
  3.  *        This puts up a standard push button. This uses the standard
  4.  *    OS push button if it is available
  5.  */
  6.  
  7. /*  YAAF - Yet another application framework
  8.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  9.  *  
  10.  *  This library is free software; you can redistribute it
  11.  *  and/or modify it under the terms of the GNU Library
  12.  *  General Public License as published by the Free Software
  13.  *  Foundation; either version 2 of the License, or any
  14.  *  later version.
  15.  *  
  16.  *  This library is distributed in the hope that it will be
  17.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  18.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  19.  *  PURPOSE. See the GNU Library General Public License for
  20.  *  more details.
  21.  *  
  22.  *  You should have received a copy of the GNU Library General
  23.  *  Public License along with this library; if not, write to the
  24.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25.  *  Boston, MA 02111-1307, USA.
  26.  *  
  27.  *  To contact the author, either e-mail me at
  28.  *  woody@alumni.caltech.edu, or write to us at
  29.  *  
  30.  *          William Edward Woody
  31.  *          In Phase Consulting
  32.  *          1545 Ard Eevin Avenue
  33.  *          Glendale, CA 91202
  34.  */
  35.  
  36. #include <XApplication.h>
  37. #include <XStdControls.h>
  38. #include <XStdButtons.h>
  39. #include <XWindow.h>
  40. #include <XError.h>
  41. #include <XDataUtil.h>
  42.  
  43. /************************************************************************/
  44. /*                                                                        */
  45. /*    Construction/Destruction                                            */
  46. /*                                                                        */
  47. /************************************************************************/
  48.  
  49. /*    XGStdPushButton::XGStdPushButton
  50.  *
  51.  *        create a push button
  52.  */
  53.  
  54. XGStdPushButton::XGStdPushButton(XGView *view, XGArgStream &stream) : 
  55.     XGStdButton(view,stream,true)
  56. {
  57.     char title[256];
  58.     stream.GetString(sizeof(title),title);
  59.  
  60.     Init(title);
  61. }
  62.  
  63. XGStdPushButton::XGStdPushButton(XGView *view, XGSButtonInitRecord &i) : 
  64.     XGStdButton(view,i.v,true)
  65. {
  66.     Init(i.title);
  67. }
  68.  
  69. /*    XGStdPushButton::~XGStdPushButton
  70.  *
  71.  *        Delete me
  72.  */
  73.  
  74. XGStdPushButton::~XGStdPushButton()
  75. {
  76. }
  77.  
  78. /************************************************************************/
  79. /*                                                                        */
  80. /*    Internal initialization                                                */
  81. /*                                                                        */
  82. /************************************************************************/
  83.  
  84. /*    XGStdPushButton::Init
  85.  *
  86.  *        The core initialization routine
  87.  */
  88.  
  89. void XGStdPushButton::Init(char *title)
  90. {
  91.     long l;
  92.     
  93.     l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
  94.     
  95. #if OPT_MACOS == 1
  96.     XGDraw draw(this,false);
  97.     Rect r;
  98.     
  99.     /*
  100.      *    Create the control at this location
  101.      */
  102.     
  103.     ::TextFont(fFont = GETHIWORD(l));
  104.     ::TextSize(fSize = GETLOWORD(l));
  105.  
  106.     r = GetContentRect();
  107.     ViewToGlobal(&r);
  108.     fControl = NewControl(GetWindow()->_GetGrafPtr(),        // window owner
  109.                           &r,                                // where
  110.                           c2pstr(title),                    // title
  111.                           true,                                // visible
  112.                           0,                                // initial value
  113.                           0,                                // min value
  114.                           1,                                // max value
  115.                           pushButProc | kControlUsesOwningWindowsFontVariant,            // push button proc
  116.                           0);                                // refcon
  117.     if (fControl == NULL) {
  118.         throw XPostError("Unable to make button ^S",p2cstr((unsigned char *)title));
  119.     }
  120. #endif
  121.  
  122. #if OPT_WINOS == 1
  123.     Rect r;
  124.     HWND w;
  125.     
  126.     /*
  127.      *    Get the location of the control in the parent's coordinate
  128.      *    system
  129.      */
  130.      
  131.     r = GetContentRect();
  132.     if (GetParent()) {
  133.         ViewToGlobal(&r);
  134.         GetParent()->GlobalToView(&r);
  135.     }
  136.     
  137.     /*
  138.      *    Create the control window
  139.      */
  140.     
  141.     w = CreateWindow("BUTTON",                    // control class
  142.                      title,                        // control title
  143.                      WS_CHILD | BS_PUSHBUTTON,    // control window flags
  144.                      r.left,
  145.                      r.top,
  146.                      r.right-r.left,
  147.                      r.bottom-r.top,            // control location
  148.                      GetParent()->_GetHWND(),    // container window
  149.                      NULL,                        // no menu
  150.                      _GInstance,                // My app instance
  151.                      NULL);                        // no additional args
  152.     if (w == NULL) {
  153.         throw XPostError("Unable to make button ^S",title);
  154.     }
  155.  
  156.     _SetHWND(w);                                // set me as the window
  157.     SetProp(w,_GViewClass,(HANDLE)this);
  158.     if (IsVisible()) ShowWindow(w,SW_SHOW);
  159.     EnableWindow(w,IsEnabled());                // set me up
  160. #endif
  161. }
  162.  
  163.